<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <title></title>
    <meta http-equiv="Content-type" content="text/html;charset=UTF-8" />

    <script type="text/javascript" src="../../resources/lib/bui/js/jquery-1.8.1.min.js"
            th:src="@{/resources/lib/bui/js/jquery-1.8.1.min.js}"></script>
    <script th:inline="javascript" type="text/javascript">
        /*<![CDATA[*/
        /**
         * 应用程序URL根路径
         * @type {string}
         * @const
         */
        var BASE_URL = /*[[@{/}]]*/ '/';
        $(function () {
            var $loginForm = $("#login_form");
            var $username = $("#username");
            var $password = $("#password");
            var $captcha = $("#captcha");
            var $isRememberUsername = $("#isRememberUsername");
            $loginForm.submit(function () {
                if ($username.val() == "") {
                    $.dialog({type: "warn", content: "请输入您的用户名!", modal: true, autoCloseTime: 3000});
                    return false;
                }
                if ($password.val() == "") {
                    $.dialog({type: "warn", content: "请输入您的密码!", modal: true, autoCloseTime: 3000});
                    return false;
                }
                if ($captcha.val() == "") {
                    $.dialog({type: "warn", content: "请输入您的验证码!", modal: true, autoCloseTime: 3000});
                    return false;
                }
                $.post(BASE_URL + "/admin/usr/login", {
                    "name" : $username.val(),
                    "passwd" : $password.val(),
                    "remeberMe":true,
                    "code":$captcha.val()
                }, function(data) {
                    if (data.ok==true) {
                        location.href=BASE_URL + '/admin/page/main';
                    } else {
                        $.dialog({type: "error", content: data.msg, modal: true, autoCloseTime: 3000});
                    }
                }, "json");
                return false;
            });
            // 刷新验证码
            var $captchaImage = $("#captchaImage");
            $captchaImage.click( function() {
                var timestamp = (new Date()).valueOf();
                var imageSrc = $captchaImage.attr("src");
                if(imageSrc.indexOf("?") >= 0) {
                    imageSrc = imageSrc.substring(0, imageSrc.indexOf("?"));
                }
                imageSrc = imageSrc + "?timestamp=" + timestamp;
                $captchaImage.attr("src", imageSrc);
            });
        });
        /*]]>*/
    </script>
</head>
<body class="login">
<div class="body">
    <form id="login_form" action="#" method="post">
        <table class="loginTable">
            <tr>
                <th>
                    用户名:
                </th>
                <td>
                    <input type="text" id="username" name="username" class="formText" />
                </td>
            </tr>
            <tr>
                <th>
                    密&nbsp;&nbsp;&nbsp;码:
                </th>
                <td>
                    <input type="password" id="password" name="password" class="formText" />
                </td>
            </tr>
            <tr>
                <th>
                    验证码:
                </th>
                <td>
                    <input type="text" id="captcha" name="code" class="formText captcha" />
                    <img id="captchaImage" class="captchaImage" th:src="@{/security/captcha}" alt="换一张" />
                </td>
            </tr>
            <tr>
                <td>
                    &nbsp;
                </td>
                <th>
                    &nbsp;
                </th>
                <td>
                    <label>
                        <input type="checkbox" id="isRememberUsername"/>&nbsp;记住用户名
                    </label>
                </td>
            </tr>
            <tr>
                <td>
                    &nbsp;
                </td>
                <th>
                    &nbsp;
                </th>
                <td>
                    <input type="submit" class="submitButton" value="登 录" />
                </td>
            </tr>
        </table>
        <div class="powered">
            COPYRIGHT © 2013
        </div>
    </form>
</div>
</body>
</html>